<%--
  Created by IntelliJ IDEA.
  User: liuchang
  Date: 2021/8/20
  Time: 17:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户信息查询</title>
    <script src="js/jquery-1.11.1.js"></script>
    <script src="js/bootstrap.js"></script>
    <link rel="stylesheet" href="css/bootstrap.css" />
    <link rel="stylesheet" href="css/bootstrap-theme.css" />
    <script>
        $(function () {
            var uname = $("[name='username']").val();
            $.ajax({
                url:"/message",
                data:"uname="+uname,
                type:"post",
                dataType:"JSON",
                success:function (rs) {
                    $("[name='pwd']").val(rs.pwd);
                    $("[name='tel']").val(rs.tel);
                    if (rs.sex=='男'){
                        //用下标0是为了将其转换为js对象
                        $("#boy")[0].checked=true;
                    }else {
                        //用下标0是为了将其转换为js对象
                        $("#girl")[0].checked=true;
                    }
                }
            })
            $("[name='username']").blur(function () {
                var uname = $(this).val();
                $.ajax({
                    url:"/message",
                    data:"uname="+uname,
                    type:"post",
                    dataType:"JSON",
                    success:function (rs) {
                        $("[name='pwd']").val(rs.pwd);
                        $("[name='tel']").val(rs.tel);
                        if (rs.sex=='男'){
                            //用下标0是为了将其转换为js对象
                            $("#boy")[0].checked=true;
                        }else {
                            //用下标0是为了将其转换为js对象
                            $("#girl")[0].checked=true;
                        }
                    }
                })
            })
        })
    </script>
</head>
<body>
    <form role="form" class="form-horizontal">
        <div class="form-group">
            <label for="queryname" class="col-md-3 col-lg-offset-2 control-label">请输入要查询的用户名</label>
            <div class="col-md-2">
                <input type="text" class="form-control" name="username" placeholder="请输入用户名" value="${sessionScope.uname}"/>
            </div>
        </div>
        <div class="form-group">
            <label for="pwd" class="col-md-3 col-lg-offset-2 control-label">密码</label>
            <div class="col-md-2">
                <input type="text" class="form-control" name="pwd" placeholder="请输入密码"/>
            </div>
        </div>
        <div class="form-group">
            <label for="sex" class="col-md-3 col-lg-offset-2 control-label">选择性别</label>
            <div class="col-md-4">
                <div class="radio">
                    <label>
                        <input type="radio" id="boy" name="sex" value="男"/>男
                    </label>
                </div>
                <div class="radio">
                    <label>
                        <input type="radio" id="girl" name="sex" value="女"/>女
                    </label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label for="tel" class="col-md-3 col-lg-offset-2 control-label">电话</label>
            <div class="col-md-2">
                <input type="tel" class="form-control" name="tel" placeholder="请输入电话"/>
            </div>
        </div>
    </form>
</body>
</html>
